data <- read.csv('worldometer_coronavirus_daily_data.csv', stringsAsFactors = TRUE)
colnames(data) <- c('Date', 'Country', 'Cumulative total cases', 'Daily new cases', 'Active cases', 'Cumulative total deaths', 'Daily new deaths')
total_deaths <- aggregate(data$`Cumulative total deaths`, by = list(data$Country), max)
total_cases <-  aggregate(data$`Cumulative total cases`, by = list(data$Country), max)

total_global <- merge(total_cases, total_deaths, by = 'Group.1')

colnames(total_global) <- c('Country' , 'Cumulative total cases', 'Cumulative total deaths')
total <- total_global[total_global$`Cumulative total cases` > 6000000,]
colnames(total) <- c('Country' , 'Cumulative total cases', 'Cumulative total deaths')
# Load required R packages
library(tidyverse)
## Warning: package 'tidyverse' was built under R version 4.2.2
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.2 ──
## ✔ ggplot2 3.4.0      ✔ purrr   0.3.5 
## ✔ tibble  3.1.8      ✔ dplyr   1.0.10
## ✔ tidyr   1.2.1      ✔ stringr 1.5.0 
## ✔ readr   2.1.3      ✔ forcats 0.5.2
## Warning: package 'ggplot2' was built under R version 4.2.2
## Warning: package 'tibble' was built under R version 4.2.2
## Warning: package 'tidyr' was built under R version 4.2.2
## Warning: package 'readr' was built under R version 4.2.2
## Warning: package 'purrr' was built under R version 4.2.2
## Warning: package 'dplyr' was built under R version 4.2.2
## Warning: package 'forcats' was built under R version 4.2.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
library(highcharter) 
## Warning: package 'highcharter' was built under R version 4.2.2
## Registered S3 method overwritten by 'quantmod':
##   method            from
##   as.zoo.data.frame zoo 
## Highcharts (www.highcharts.com) is a Highsoft software product which is
## not free for commercial and Governmental use
library(ggplot2)

# Set highcharter options
options(highcharter.theme = hc_theme_smpl(tooltip = list(valueDecimals = 2)))
highchart() %>%
  hc_title(text = "Cases and Deaths per country") %>%
  hc_xAxis(categories = total$Country, title = 'Country') %>% 
  hc_yAxis_multiples(create_axis(naxis = 2, heights = c(2, 1))) %>%
  hc_add_series(total$`Cumulative total cases` , yAxis = 0, name = 'Cases') %>%
  hc_add_series(total$`Cumulative total deaths`, yAxis = 1, name = 'Deaths') %>%
  hc_legend(
    align = "left",
    verticalAlign = "middle",
    layout = "vertical"
    )
highchart() %>%
  hc_title(text = "Cases vs. Deaths per country") %>%
  hc_xAxis(categories = total$Country, title = 'Country') %>% 
  hc_add_series(total$`Cumulative total cases`, name = 'Cases') %>%
  hc_add_series(total$`Cumulative total deaths`, name = 'Deaths') %>%
  hc_legend(
    align = "left",
    verticalAlign = "middle",
    layout = "vertical"
    )

A continuación seleccionamos los 6 países con más casos para nuestra próxima visualización:

total <- total %>%                                      # Top N highest values by group
  arrange(desc(`Cumulative total cases`))
head(total)
data_series <- na.omit(data[data$Country %in% c('USA', 'India', 'Brazil', 'France', 'Germany', 'UK'),])

data_series$Population <- as.numeric(ifelse(data_series$Country == 'USA', 331900000,
                                    ifelse(data_series$Country == 'UK', 67330000, 
                                    ifelse(data_series$Country == 'India', 1393000000, 
                                    ifelse(data_series$Country == 'Brazil', 214000000,
                                    ifelse(data_series$Country == 'France', 67500000,
                                    ifelse(data_series$Country == 'Germany', 83130000,
                                    0)))))))

data_series$`Cumulative total cases by population` = data_series$`Cumulative total cases` / data_series$Population
data_series$`Cumulative total deaths by population %` = data_series$`Cumulative total deaths` / data_series$Population*100
data_series$`Daily new cases by population` = data_series$`Daily new cases` / data_series$Population
data_series$`Daily new deaths by population %` = data_series$`Daily new deaths` / data_series$Population*100
hc1 <- data_series %>% 
  hchart('line', hcaes(x = Date, y = `Cumulative total cases`, group = Country)) %>%
  hc_title(text = "Cumulative cases per country") %>%
  hc_legend(
    align = "left",
    verticalAlign = "middle",
    layout = "vertical"
    )

hc2 <- data_series %>% 
  hchart('line', hcaes(x = Date, y = `Cumulative total cases by population`, group = Country)) %>%
  hc_title(text = "Cumulative total cases / population per country ") %>%
  hc_legend(
    align = "left",
    verticalAlign = "middle",
    layout = "vertical"
    )

par(mfrow=c(2,1))

hc1
hc2
hc3 <- data_series %>% 
  hchart('line', hcaes(x = Date, y = `Cumulative total deaths`, group = Country)) %>%
  hc_title(text = "Cumulative deaths per country") %>%
  hc_legend(
    align = "left",
    verticalAlign = "middle",
    layout = "vertical"
    )

hc4 <- data_series %>% 
  hchart('line', hcaes(x = Date, y = `Cumulative total deaths by population %`, group = Country)) %>%
  hc_title(text = "Cumulative total deaths over population percentage per country") %>%
  hc_legend(
    align = "left",
    verticalAlign = "middle",
    layout = "vertical"
    )

par(mfrow=c(2,1))

hc3
hc4
hc5 <- data_series %>% 
  hchart('column', hcaes(x = Date, y = `Daily new cases`, group = Country)) %>%
  hc_title(text = "Daily new cases per country") %>%
  hc_legend(
    align = "left",
    verticalAlign = "middle",
    layout = "vertical"
    )

hc5

Finalment observam la tasa de mortalitat per país:

hc6 <- data_series %>% 
  hchart('column', hcaes(x = Date, y = `Daily new deaths`, group = Country)) %>%
  hc_title(text = "Daily new deaths per country") %>%
  hc_legend(
    align = "left",
    verticalAlign = "middle",
    layout = "vertical"
    )

hc6
total_global <- total_global[total_global$`Cumulative total cases` > 1000000,]
total_global$`Death rate percentage` = total_global$`Cumulative total deaths`/total_global$`Cumulative total cases`*100

total_global <- total_global %>%                                    
  arrange(desc(`Death rate percentage`))
head(total_global)

Porcentaje mortalidad/caso en aquellos países con más de un millón de casos acumulados

highchart() %>%
  hc_title(text = "Death/case rate percentage per country") %>%
  hc_xAxis(categories = total_global$Country, title = 'Country') %>% 
  hc_add_series(total_global$`Death rate percentage` , name = 'Death rate') %>%
  hc_legend(
    align = "left",
    verticalAlign = "middle",
    layout = "vertical"
    )